#ifndef _INPUTHANDLER_
#define _INPUTHANDLER_

#include "SFML/Window/Mouse.hpp"
#include "SFML/Window/Keyboard.hpp"


/** 
* Mouse and keyboard input handler.
* Abstracts SFML's input methods. Implemented for easy porting and also to
* provide a frame based input state, instead of polling the os on every call.
*/
class InputHandler{
private:
    /** Last time of update. */
    unsigned int lastUpdateTime;

    /** Singleton instance. */
    static InputHandler* instance;
public:

    /** Has the left mouse button been pressed this frame. */
    bool leftPressed;
    /** Has the right mouse button been pressed this frame. */
    bool rightPressed;

    /** Is the left mouse button pressed. */
    bool leftDown;
    /** Is the right mouse button pressed. */
    bool rightDown;

    /** Has the left mouse button been released this frame.*/
    bool leftReleased;
    /** Has the right mouse button been released this frame. */
    bool rightReleased;

    /** Last time the left mouse button was pressed. */
    unsigned int lastLeftPressedTime;
    /** Last time the right mouse button was pressed. */
    unsigned int lastRightPressedTime;

    /** Last time the left mouse button was pressed. */
    unsigned int lastLeftReleasedTime;
    /** Last time the right mouse button was pressed. */
    unsigned int lastRightReleasedTime;

    /** Has the left mouse button been double clicked this frame. */
    bool doubleClick;
    /** Max time between two left mouse clicks to count as double click. */
    unsigned int doubleClickSpeed;

    /** Mouse X position.*/
    int mouseX;
    /** Mouse Y position. */
    int mouseY;
    
    int mouseWorldX;
    int mouseWorldY;
    
    InputHandler();
    
    InputHandler* I();
    
    void update(unsigned int time);
    bool isKeyPressed(sf::Keyboard::Key key);
};

#endif
